#include <iostream>

using namespace std;


class binaryTreeNode
{
	int element;
	binaryTreeNode* leftChild;
	binaryTreeNode* rightChild; 
	binaryTreeNode() { leftChild=rightChild = NULL; }  
	binaryTreeNode(int theElement) { element = theElement; leftChild=rightChild=NULL;}
	binaryTreeNode(int theElement,binaryTreeNode*theleftChild,binaryTreeNode*therightChild)  { element = theElement; leftChild=theleftChild;rightChild=therightChild; }
};


void getpostOrder( int n,char* a,char* b)
{
	if(n==0)
	{
		return;
	}
	char data = * a;
	int rootpos=0;
	for(;rootpos<n;rootpos++)
	{
		if(*a ==b[rootpos])
		   break;
	} 
	
	getpostOrder(rootpos,a+1,b);
	getpostOrder(n-(rootpos+1),a+rootpos+1,b+rootpos+1);
	cout<<data<<" ";
	
}






int main()
{
	int n=0;
	cin>>n;
	char a[100],b[100];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	getpostOrder(n,a,b);
} 
